package com.anjubao.parking.municipal.parkinglot.controller;


import com.anjubao.parking.municipal.common.dto.ApiResult;
import com.anjubao.parking.municipal.parkinglot.dto.ParkingStatFailuresDevicesDto;
import com.anjubao.parking.municipal.parkinglot.dto.ParkingStatFailuresZonesDto;
import com.anjubao.parking.municipal.parkinglot.service.ParkingStatFailuresService;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 区域运维事件统计API
 * @author anjubao
 */
@RestController
@RequestMapping("/parking-stat-failures-records")
@Api(value = "ParkingStatFailuresController",tags = {"区域运维事件统计API"})
public class ParkingStatFailuresController {

    @Autowired
    private ParkingStatFailuresService parkingStatFailuresService;
    private static final Logger logger = LoggerFactory.getLogger(ParkingStatFailuresController.class);

    /**
     * 各区域运维事件排名/故障设备占比统计
     * @param tab
     * @param cityId
     * @return
     */
    @ApiOperation(value = "各区域运维事件排名/故障设备占比统计",notes = "分区域统计事件数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tab", value = "统计时间(默认month) 本周:week,上周:pre-week,本月:month ,区域列表:all",dataType ="String"),
            @ApiImplicitParam(name = "cityId", value = "所属城市",dataType ="int")
    })
    @ApiResponses(value = {
            @ApiResponse(code = 5000,message = "操作失败")
    })
    @GetMapping("/zones")
    public ApiResult<List<ParkingStatFailuresZonesDto>> getFailuresRecordsZones(Integer cityId,@RequestParam(required = false)String tab) {
        logger.info("分区域统计事件数 {} ", cityId,tab);
        List<ParkingStatFailuresZonesDto> failuresRecordsZonesList=parkingStatFailuresService.getFailuresRecordsZones(cityId,tab);
        return ApiResult.success(failuresRecordsZonesList);
    }

    /**
     * 设备运维事件占比统计
     * @param cityId
     * @return
     */
    @ApiOperation(value = "设备运维事件占比统计",notes = "最近30天分设备统计事件占比")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cityId", value = "所属城市",dataType ="int")
    })
    @ApiResponses(value = {
            @ApiResponse(code = 5000,message = "操作失败")
    })
    @GetMapping("/devices")
    public ApiResult<List<ParkingStatFailuresDevicesDto>> getFailuresRecordsDevices(Integer cityId) {
        logger.info("最近30天分设备统计事件占比 {} ",cityId);
        List<ParkingStatFailuresDevicesDto> failuresRecordsDevicesList=parkingStatFailuresService.getFailuresRecordsDevices(cityId);
        return ApiResult.success(failuresRecordsDevicesList);
    }
}
